package com.baizhi.service.impl;

import com.baizhi.dao.ProductDao;
import com.baizhi.entity.Product;
import com.baizhi.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yystart
 * @create 2019-10-04 16:46
 */
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductDao dao;

    @Override
    public Map selectProductsByPage(int page, int limit) {
        int offset = page*limit - limit;
        List<Product> products = dao.selectProductsByPage(offset, limit);
        int totalCount = dao.selectTotalCount();

        Map map = new HashMap();
        map.put("data",products);
        map.put("count",totalCount);
        map.put("code",0);
        map.put("msg","");

        return map;
    }

    @Override
    public Product selectOne(int id) {
        return dao.selectOne(id);
    }
}
